package com.brainhealth.web.controller.customer;

import com.brainhealth.common.annotation.Anonymous;
import com.brainhealth.common.core.controller.BaseController;
import com.brainhealth.common.core.domain.AjaxResult;
import com.brainhealth.customer.domain.params.RoomChatParam;
import com.brainhealth.customer.domain.vo.ChatAiContentVO;
import com.brainhealth.customer.domain.vo.RemainChatVO;
import com.brainhealth.customer.domain.vo.RoomChatVO;
import com.brainhealth.customer.service.IRoomChatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 陪伴小屋聊天
 */
@RequestMapping("/room/chat/v1")
@RestController
public class RoomChatController extends BaseController {

    @Autowired
    IRoomChatService roomChatService;

    @Anonymous
    @GetMapping("/get_remain_chat_packet")
    public AjaxResult getRemainChatPacket(HttpServletRequest request) {
        RemainChatVO remainChatPacket = roomChatService.getRemainChatPacket(request);
        if (null == remainChatPacket) {
            return error("查询用户剩余语言包异常");
        }
        return success(remainChatPacket);
    }

    @Anonymous
    @PostMapping("/get_chat_content")
    public AjaxResult getChatContent(HttpServletRequest request, @RequestBody RoomChatParam roomChatParam) {
        ChatAiContentVO chatContent = roomChatService.getChatContent(request, roomChatParam);
        if (null == chatContent) {
            return error("查询聊天内容异常");
        }
        return success(chatContent);
    }

    @Anonymous
    @GetMapping("/get_chat_list")
    public AjaxResult getChatList(HttpServletRequest request) {
        List<RoomChatVO> chatList = roomChatService.getChatList(request);
        if (null == chatList) {
            return error("查询历史聊天记录异常");
        }
        return success(chatList);
    }

}
